﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MvcEngine.Core.Repositories;

using System.Data.Linq;
using MvcEngine.Core;
using MvcEngine.Core.Website;

namespace MvcEngine.LinqToSqlProvider
{
    public class SkinTemplateRepository : Repository, ISkinTemplateRepository
    {
        public SkinTemplate Get(Guid id)
        {
            using (var contextManager = CreateContextManager(true))
            {
                return contextManager.Context.SkinTemplates().Single(s => s.Id == id);
            }
        }

        public IList<SkinTemplate> GetAll(Guid skinId)
        {
            using (var contextManager = CreateContextManager(true))
            {
                return contextManager.Context.SkinTemplates().Where(s => s.SkinId == skinId).ToList();
            }
        }

        public SkinTemplate GetDefault(Guid skinId)
        {
            using (var contextManager = CreateContextManager(true))
            {
                return contextManager.Context.SkinTemplates().SingleOrDefault(s=> s.SkinId == skinId && s.IsDefault == true);
            }
        }
    }
}
